package cmd

import (
	"context"
	"fmt"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"mongofix/quit_all_group"
)

var exitAll bool
var kick bool

var uid string
var groupId string

var group = &cobra.Command{
	Use:     "group",
	Short:   "群管理命令",
	Long:    "群管理命令",
	Version: "1.0",
	Run:     Run,
}

func Run(cmd *cobra.Command, args []string) {
	ctx := context.Background()
	if exitAll {
		if uid == "" {
			log.Infof("退群的uid为空")
			return
		}
		quit_all_group.QuitAllGroup(ctx, uid)
	} else if kick {
		quit_all_group.Kick(ctx, groupId, uid)
	} else {
		fmt.Println("不支持的群功能")
	}
}

func init() {
	group.Flags().BoolVar(&exitAll, "exitAll", false, "退出所有的群")
	group.Flags().BoolVar(&kick, "kick", false, "提出群成员")
	group.Flags().StringVarP(&uid, "uid", "u", "", "退群的用户ID")
	group.Flags().StringVarP(&groupId, "groupId", "g", "", "群ID")
	rootCmd.AddCommand(group)
}
